$(function () {
    addUploadBtn();
});

function addUploadBtn() {
    var html = "<div class=\"form-group\">\n" +
        "                <label class=\"col-sm-3 control-label\">上传报告：</label>\n" +
        "                <div class=\"col-sm-8\">\n" +
        "                    <input name=\"file\" class=\"form-control\" type=\"file\" style=\"display: inline-block;width: 80%;\">\n" +
        "                    <a class=\"btn btn-success\" style=\"margin-left: 4px;height: 31px;vertical-align: top;\" href=\"javascript:void(0)\" onclick=\"upload()\"><i class=\"fa fa-upload\"></i>上传</a>\n" +
        "                </div>\n" +
        "            </div>";
    $("form").append(html);
}

function upload() {
    var formData = new FormData();
    formData.append("file",$('[name="file"]')[0].files[0]);
    $.ajax({
        url:'/module/report/upload',
        dataType:'json',
        type:'POST',
        async: false,
        data: formData,
        processData : false, // 使数据不做处理
        contentType : false, // 不要设置Content-Type请求头
        success: function(data){
            console.log(data);
            for(var key in data){
                var value = data[key];
                $('input[name="'+key+'"]').val(value);
            }
        },
        error:function(response){
            console.log(response);
        }
    });
}